package com.wuyunonline.tracelog.interceptor;

import com.wuyunonline.tracelog.common.constant.TraceLogConstant;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
import org.jetbrains.annotations.NotNull;
import org.slf4j.MDC;

import java.io.IOException;


/**
 * Okhttp traceId拦截器
 * @author wuyun
 */
public class TraceLogOkhttpInterceptor implements Interceptor {

    @Override
    public Response intercept(@NotNull Chain chain) throws IOException {
        Request request = chain.request().newBuilder()
                .addHeader(TraceLogConstant.TRACE_ID, MDC.get(TraceLogConstant.TRACE_ID))
                .build();
        return chain.proceed(request);
    }
}
